﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;

using libReadWrite;
using libCommonClass;

namespace TTServer.Messages
{
    public class AdminAuthentificationResponseMessage : TTMessage
    {
        private bool _authenticated = false;

        public bool Authenticated
        {
            get { return _authenticated; }
            set { _authenticated = value; }
        }

        //private string _tempKey = "";

        //public string TempKey
        //{
        //    get { return _tempKey; }
        //    set { _tempKey = value; }
        //}

        private byte[] _encryptedTempKey;

        public byte[] EncryptedTempKey
        {
            get { return _encryptedTempKey; }
            set { _encryptedTempKey = value; }
        }

        public AdminAuthentificationResponseMessage()
        {

        }

        public AdminAuthentificationResponseMessage(bool bAuthentification, byte[] encryptedTempKey)
        {
            this._authenticated = bAuthentification;
            this._encryptedTempKey = encryptedTempKey;
        }

        public override void ReadMessage(BigEndianReader sr)
        {
            throw new NotImplementedException();
        }

        public override void WriteMessage(BigEndianWriter sw)
        {
            sw.Write((byte)MessageKind.ADMIN_AUTHENTIFICATION_RESPONSE);
            sw.Write(Global.NO_LENGTH_CODE); 
            sw.Write((byte)(_authenticated == true ? 1 : 0));
            //sw.WriteString(_tempKey);
            sw.WriteByteArray(_encryptedTempKey);
        }

        public override TTMessage Clone()
        {
            return (new AdminAuthentificationResponseMessage());
        }

        public override int GetMessageID()
        {
            return MessageKind.ADMIN_AUTHENTIFICATION_RESPONSE;
        }

        public override string GetMessageName()
        {
            return "AuthentificationResponse";
        }
    }
}
